<template>
  <div class="mine-root">
    <div class="flex-btw bg-box">
      <div class="user-info">
        <van-image
          v-if="userInfo.src"
          round
          width="1.46rem"
          height="1.46rem"
          :src="userInfo.src"
        />
        <div v-if="!userInfo.src" class="src-box">
          <van-icon name="friends" color="#ccc" />
        </div>

        <div class="info">
          
          <div class="name">{{ userInfo.username }}</div>
          <div class="vip" v-if="userInfo.vip > 0"><font style="color:#fea424;">会员</font>
            <font v-if="!userInfo.vip_expire">（永久）</font>
            <font v-else-if="userInfo.vip_effective">（{{ userInfo.vip_expire }}）</font>
            <font v-else style="color:red;">（过期，禁止交易）</font>
          </div>
          <div class="vip" v-else >未激活会员<font style="color:red;">（禁止交易）</font></div>

          <div class="account" >{{ userInfo.nickname }}</div>
        </div>
      </div>

      <div class="level" @click="showBox = true" v-if="!userInfo.vip || userInfo.vip_expire">
        <font v-if="!userInfo.vip_expire">会员激活</font>
        <font v-else>会员续期</font>
      </div>

      <img
        class="tools"
        @click="$router.push('/sysSetting')"
        src="../../assets/images/mine/7.png"
        alt=""
      />
    </div>

    <div
      class="row"
      v-for="item in navList"
      :key="item.title"
      @click="$router.push(item.url)"
    >
      <div class="title-box flex">
        <img :src="item.icon" alt="" />
        <div class="title">{{ item.title }}</div>
      </div>

      <img src="../../assets/images/mine/6.png" alt="" />
    </div>

    <!-- 用户激活弹出层 -->
    <van-popup
      round
      position="center"
      v-model="showBox"
      style="border-radius: 0.1rem"
    >
      <div class="box">
        <div class="title">用户激活</div>

        <div class="main">
          <div class="content">
            <div class="name">激活类型</div>
            <div class="value flex-btw" @click="showSelect = true">
              <div class="text">{{ value }}</div>
              <div class="icon">
                <van-icon name="play" color="#1989fa" />
              </div>
            </div>
            <div class="money flex-btw">
              <div class="text">需支付</div>
              <div class="num">{{ vipList[value]['money'] }}</div>
              <div class="text">USDT</div>
            </div>
          </div>
        </div>

        <div class="btn-box flex">
          <div class="btn" @click="showBox = false">取消</div>
          <div class="btn" @click="activation()">激活</div>
        </div>
      </div>
    </van-popup>

    <!-- 激活方式弹出层 -->
    <van-popup position="bottom" v-model="showSelect">
      <van-picker
        show-toolbar
        :columns="columns"
        @confirm="onConfirm"
        @cancel="onCancel"
        @change="onChange"
      />
    </van-popup>
  </div>
</template>

<script>
import mixin from "@/mixin.js";
import { Toast , Notify } from "vant";
import { PERSON , MINE_ACTIVATE_VIP } from "@/api/api.js";
export default {
  name: "mine",
  components: {},
  data() {
    return {
      navList: [
        {
          title: "资产",
          icon: require("@/assets/images/mine/1.png"),
          url: "/wallet",
        },
        {
          title: "交易记录",
          icon: require("@/assets/images/mine/2.png"),
          url: "/transactionHis?rule_id=0",
        },
        {
          title: "社区",
          icon: require("@/assets/images/mine/3.png"),
          //url: "/community",
        },
        {
          title: "分享",
          icon: require("@/assets/images/mine/4.png"),
          //url: "/share",
        },
        {
          title: "关于我们",
          icon: require("@/assets/images/mine/5.png"),
        },
      ],
      columns: ['月激活','永久激活'],
      vipList : {
        '月激活': {
          'type': '1',
          'money': '15.00',
        },
        '永久激活': {
          'type': '2',
          'money': '150.00',
        },
      },
      showBox: false,
      showSelect: false,
      value: "月激活",
      userInfo: [],
    };
  },
  mounted() {
    this.getUserInfo();
  },
  methods: {
    async getUserInfo() {
      const { data } = await this.$reqGet(PERSON);
      if (data.status == 1) {
        this.userInfo = data.data;
      }
    },
    onConfirm(value, index) {
      this.value = value;
      this.showSelect = false;
    },
    onChange(picker, value, index) {},
    onCancel() {},
    // 激活
    async activation() {
      // 请求参数
      const param = this.vipList[this.value];
      param.vip = this.userInfo.vip;
      param.vip_expire = this.userInfo.vip_expire;
      const { data } = await this.$reqPost(MINE_ACTIVATE_VIP, param);
      if (data.status === 1) {
        this.userInfo.vip = data.data.vip;
        this.userInfo.vip_expire = data.data.vip_expire;
        this.userInfo.vip_effective = data.data.vip_effective;
        Toast('会员激活成功');

        this.showBox = false;
      } else if(data.status === 0){
        Toast(data.info);
      }

     //
    },
  },
};
</script>
<style lang="scss" scoped>
.mine-root {
  .bg-box {
    position: relative;
    width: 100%;
    height: 3.3rem;
    background: url("../../assets/images/mine/bg.png");
    background-size: 100% 100%;
    background-position: 0 0;
    padding: 0 0.33rem;
    align-items: center;

    .user-info {
      display: flex;
      align-items: flex-end;
      .info {
        margin-left: 0.4rem;
        .name {
          text-align: left;
          font-size: 0.3rem;
          color: #fff;
          margin-bottom: 0.1rem;
        }

        .vip {
          text-align: left;
          color: #dedede;
          font-size: 0.24rem;
          margin-bottom: 0.1rem;
        }

        .account {
          text-align: left;
          color: #fff;
          font-size: 0.24rem;
        }
      }

      .src-box {
        width: 1.46rem;
        height: 1.46rem;
        background-color: #f8f8f8;
        display: flex;
        justify-content: center;
        align-items: center;
        border-radius: 50%;
      }
    }

    .level {
      border-radius: 0.25rem;
      width: 1.57rem;
      height: 0.5rem;
      background-color: #fea424;
      font-size: 0.26rem;
      line-height: 0.5rem;
      color: #fff;
    }

    .tools {
      top: 0.3rem;
      right: 0.3rem;
      width: 0.34rem;
      height: 0.34rem;
      position: absolute;
    }
  }

  .row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0.33rem;
    height: 1rem;
    background-color: #fff;
    border-bottom: 0.04rem solid #faf9f9;

    &:nth-child(3) {
      border-bottom: 0.1rem solid #dbdbdb;
    }

    .title-box {
      font-size: 0.3rem;
      color: #141414;

      img {
        width: 0.32rem;
        height: 0.32rem;
        margin-right: 0.34rem;
      }
    }

    img {
      width: 0.12rem;
      height: 0.2rem;
    }
  }

  .box {
    .title {
      color: #2e2e2e;
      font-size: 0.28rem;
      margin: 0.3rem;
    }

    .main {
      margin: 0 0.3rem 0.3rem;
      background-color: #eeeeee;

      .content {
        width: 4.7rem;
        font-size: 0.28rem;
        padding: 0.3rem 0.8rem;
        .name {
          text-align: left;
          margin-bottom: 0.3rem;
        }
        .value {
          margin-bottom: 0.3rem;

          .icon {
            transform: rotate(90deg);
          }
        }
        .money {
          .num {
            color: #ce5065;
          }
        }
      }
    }

    .btn-box {
      margin-top: 0.1rem;
      border-top: 0.02rem solid #aeaeae;
      .btn {
        padding: 0.3rem;
        flex: 1;
        font-size: 0.28rem;

        &:nth-child(2) {
          border-left: 0.01rem solid #aeaeae;
          color: #2d7afe;
        }
      }
    }
  }
}
</style>
